class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        int len = tokens.size();
        if(len <= 1){ return atoi(tokens[0].c_str()); }
        stack<int> num;
        for(int i = 0; i < len; ++i){
            string& s = tokens[i];
            if(s != "+" && s != "-" && s != "*" && s != "/" ){
                num.push(atoi(s.c_str()));  // 将要计算的数字入栈
            }
            else{  //是操作符
                // 将两个运算数字出栈赋值给num1,num2
                int back = num.top();   
                num.pop();
                int front = num.top();
                num.pop();
                switch (s[0]){
                    case '+' : num.push(front + back);
                        break;
                    case '-' : num.push(front - back);
                        break;
                    case '*' : num.push(front * back);
                        break;
                    case '/' : num.push(front / back);
                        break;
                    default: break;
                }
            }
        }
        return num.top();
    }
};